package com.pybox.api;

import com.pybox.service.TDeptService;
import com.pybox.dto.TDeptDto;

import com.pybox.dto.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.*;

/**
* 描述：TDept Api
* @author wuyingkai
* @date 2018-09-15
*/

@Slf4j
@RequestMapping("/TDept")
@ApiIgnore
@Api(tags = "TDept管理接口", description = "TDept管理接口")
@RestController
public class TDeptApi {

    @Autowired
    private TDeptService service;

    @ApiOperation(value = "创建TDept", notes = "创建TDept")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result<Boolean> save(@RequestBody TDeptDto dto) {
        service.create(dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "删除TDept", notes = "删除TDept")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(name = "id", value = "TDept id", dataType = "String", paramType = "path")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        service.delete(id);
        return Result.ok(true);
    }

    @ApiOperation(value = "更新TDept", notes = "更新TDept")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @ApiImplicitParam(name = "id", value = "TDept id", dataType = "String", paramType = "path")
    public Result<Boolean> update(@PathVariable("id") Integer id, @RequestBody TDeptDto dto) {
        service.update(id, dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "查询TDept", notes = "查询TDept")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "TDept id", dataType = "String", paramType = "path")
    public Result<TDeptDto> detail(@PathVariable("id") Integer id) {

        return Result.ok(service.detail(id));
    }

    @ApiOperation(value = "分页查询TDept", notes = "分页查询TDept")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
           @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "query"),
           @ApiImplicitParam(name = "parentId", value = "parentId", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "ancestors", value = "ancestors", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "deptName", value = "deptName", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "orderNum", value = "orderNum", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "leader", value = "leader", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "phone", value = "phone", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "email", value = "email", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "status", value = "status", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "delFlag", value = "delFlag", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "createBy", value = "createBy", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "ctime", value = "ctime", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "updateBy", value = "updateBy", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "utime", value = "utime", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TDeptDto>> page(
                        @RequestParam(required = false) Integer id,
                        @RequestParam(required = false) String parentId,
                        @RequestParam(required = false) String ancestors,
                        @RequestParam(required = false) String deptName,
                        @RequestParam(required = false) String orderNum,
                        @RequestParam(required = false) String leader,
                        @RequestParam(required = false) String phone,
                        @RequestParam(required = false) String email,
                        @RequestParam(required = false) String status,
                        @RequestParam(required = false) String delFlag,
                        @RequestParam(required = false) String createBy,
                        @RequestParam(required = false) String ctime,
                        @RequestParam(required = false) String updateBy,
                        @RequestParam(required = false) String utime,
                    @RequestParam(required = true) Integer pageNo,
                    @RequestParam(required = true) Integer pageSize) {

        Map<String, String> params = new HashMap<>();
                params.put("parentId",parentId);
                params.put("ancestors",ancestors);
                params.put("deptName",deptName);
                params.put("orderNum",orderNum);
                params.put("leader",leader);
                params.put("phone",phone);
                params.put("email",email);
                params.put("status",status);
                params.put("delFlag",delFlag);
                params.put("createBy",createBy);
                params.put("ctime",ctime);
                params.put("updateBy",updateBy);
                params.put("utime",utime);
        return Result.ok(service.page(pageNo, pageSize, params));
    }
}